﻿using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.Global;
using Transformable_Engine_v2.Engine.Graphics;
using Transformable_Engine_v2.Engine.Rendering;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace Transformable_Engine_v2.Engine.GameObjects.Primitives
{
    public class CirclePrimitive : Container
    {
        public override TE_Vector2 AbsolutePosition
        {
            protected set
            {
                base.AbsolutePosition = value;
                if(_circleShape != null)
                    _circleShape.Position = AbsolutePosition.ToVector2f();
            }
        }

        public uint PointCount
        {
            set
            {
                _circleShape.SetPointCount(value);
            }
        }

        public float Radius
        {
            set
            {
                _circleShape.Radius = value * Game.Options.GridSize;
            }
        }

        public TE_Circle Shape
        {
            set
            {
                Radius = value.Radius;
                Position = value.Center.ToGridbound();
            }   
        }

        public Color FillColor
        {
            set
            {
                _circleShape.FillColor = value.ToSFMLColor();
            }
        }

        public Color OutlineColor
        {
            set
            {
                _circleShape.OutlineColor = value.ToSFMLColor();
            }
        }

        public int OutlineThickness
        {
            set
            {
                _circleShape.OutlineThickness = value;
            }
        }

        private readonly SFML.Graphics.CircleShape _circleShape;

        public CirclePrimitive()
        {
            _circleShape = new  SFML.Graphics.CircleShape();
        }

        public override void Draw()
        {
            if(Visible)
            {
                if (ShaderHandler.HasShader)
                    RenderTargetHandler.GetCurrentRenderTarget().Draw(_circleShape, ShaderHandler.CurrentShader);
                else
                    RenderTargetHandler.GetCurrentRenderTarget().Draw(_circleShape);
            }
        }
    }
}